package com.hxf.service.appraisal.impl;

import org.springframework.stereotype.Repository;

import com.hxf.dto.AdminUserDto;
import com.hxf.dto.AppraisalDto;
import com.hxf.dto.ReturnData;
import com.hxf.exception.DaoLevelException;
import com.hxf.exception.ServiceException;
import com.hxf.service.appraisal.AppraisalService;
import com.hxf.service.base.impl.BaseServiceImpl;

@SuppressWarnings("unchecked")
@Repository("appraisalService")
public class AppraisalServiceImpl extends BaseServiceImpl implements AppraisalService {

	@Override
	public ReturnData<AppraisalDto> findAppraisal(AppraisalDto appraisalDto,
			int targetPage, int pageSize) throws ServiceException {
		try {
			return super.daoFacade.getAppraisalDao().findAppraisal(appraisalDto, targetPage, pageSize);
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		}
	}

	@Override
	public void updateUserStatus(String userIds, Integer status)
			throws ServiceException, DaoLevelException {
		try {
			AppraisalDto ud = null;
			 if (!"".equals(userIds) && null != userIds) {
				  String userId [] = userIds.split(",");
				  if (null != userId) {
					  for (int i = 0;i < userId.length; i++) {
						  ud = (AppraisalDto)super.daoFacade.getAppraisalDao().get(AppraisalDto.class, Integer.parseInt(userId[i]));
						  ud.setStatus(status);
						  super.daoFacade.getAppraisalDao().update(ud);
					  }
				  }
			 } 
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		}
	}

}
